<template>
	<view>
		<scroll-view scroll-x class="bg-white nav">
			<view class="header flex text-center">
				<!-- :class="{'setfixeds':setfixeds==true}" -->
				<view class="cu-item flex-sub f-size"  >
					<button class="cu-btn btn_header_width setfixeds"  @tap="quotes()">引用</button>
					<button class="cu-btn btn_header_width setfixeds"  @tap="selectorder()">查单</button>
					<button class="cu-btn btn_header_width setfixeds"  @tap="selectsource">查看源单</button>
					<button class="cu-btn btn_header_width setfixeds"  @tap="AddBillOrder">保存单据</button>
				</view>
			</view>  
			<view class="main">
				<view class="main-box">
					<form> 
						<view  class="cg-main">
							<view class="sticky">
								<view class="cu-form-group">
									<!-- <view class="title">单据编号：{{checkdata.BillNo}}</view> -->
									<view class="title">单据编号：</view>
									<input :value="checkdata.BillNo" placeholder="请先建立单据" disabled="true">
								</view>
								<view class="cu-form-group" @tap="changeShow('QS_Picekr_date',0)">
									<view class="title">单据日期：</view>
									<!-- <view @tap="open()" class="inpt1"> -->
										<!-- timeData.fulldate -->
										<input placeholder="点击选择<单据日期>" :value="checkdata.BillTime" disabled="true"></input>
									<!-- </view> -->
								</view>
								<view class="cu-form-group" @tap="clicktoclient">
								<!-- <view class="cu-form-group" @tap="clickopen(1,'供应商')"> -->
									<view class="title">供 应 商 ：</view>
									<!-- <span style="color: red;">*</span> -->
									<!-- checkedClientList.ClientName -->
									<input type="text" :value="checkdata.BName" disabled="true" placeholder="点击选择<供应商>">
									<view @tap.stop="ckechdempty(1)" class="empty">清空</view>
									<!-- <view class="supplieruser">{{checkdata.BName}}</view> -->
								</view>
								<view class="cu-form-group" @tap="clickopen(2,'仓库')">
									<view class="title">仓　　库：</view>
									<!-- checkedwarehouse.StoreName -->
									<input disabled="true" :value="checkdata.stockName" placeholder="点击选择<仓库>">
									<view @tap.stop="ckechdempty(2)" class="empty">清空</view>
									<!-- <view class="supplieruser">{{checkdata.stockName}}</view> -->
								</view>
								<view class="cu-form-group" @tap="clickopen(3,'业务员')">
									<view class="title">业 务 员 ：</view>
									<!-- checksalesman.OperatorName -->
									<input disabled="true" :value="checkdata.EName" placeholder="点击选择<业务员>">
									<view @tap.stop="ckechdempty(3)" class="empty">清空</view>
									<!-- <view class="supplieruser">{{checkdata.EName}}</view> -->
								</view>
								<view class="cu-form-group">
									<view class="title">本次付款：</view>
									<input class="inpt" type="number" name="input" maxlength="7" placeholder="请输入本次付款"  v-model="CollectAmount"></input>
								</view>
								<view class="cu-form-group" v-show="more">
										<view class="title">抹零金额：</view>
										<input class="inpt" maxlength="7" placeholder="请输入抹零金额" type="number" name="input" v-model="NoSmallAmount"></input>
								</view>
								<view class="cu-form-group" v-show="more">
									<view class="title">备　　注：</view>
									<input placeholder="请输入备注" v-model="BillRemark" ></input>
								</view>
								<view class="cu-form-group" v-show="more">
									<view class="title">制 单 人 ：　{{CreateName}}</view>
								</view>
								<view  class="cu-form-group" @tap="clickmore" style="display: flex;justify-content: center;align-items: center;">
								    <view v-if="more">收起更多</view>
								    <view v-else>更多</view>
								</view>
							<view>
								<view class="searchInput">
									<view class="goodFilter">
										<uniIcons type="search" size="14" style="line-height: 28px;margin-left: 5px;margin-right: 5px;color: #a7aab3;" /><input
										 placeholder="输入条码进行搜索" class="searchOption" confirm-type="search" type="text" @confirm="search()" v-model.trim="searchKey"></input>
										 </uniIcons>
									</view>
									<view class="searchOptions">
										<button class="giveSong" @tap="AddGood()">
											<img src="../../static/image/add.png" alt="">
										</button>
										<button class="getPicture" @tap="tel()"></button>
									</view>
								</view>
							</view>
							<view class="cu-form-group" style="justify-content: space-around;position: fixed;width: 100%;bottom: 0;left: 0;z-index: 999;">
								<!-- <button class="cu-btn  stop text-white" @tap="addSelectGoods" :style="{visibility:isSelectGood?'':'hidden'}">确定商品</button>
								<view class="inpt">
									<button class="cu-btn  stop text-white" @tap="selectsource" >查看源单</button>
								</view>
								<button class="cu-btn  stop text-white" @tap="AddBillOrder">保存单据</button> -->
								<!-- <view style="color: #e54d42;font-size: 13px;">未验数：{{noapproved}}</view>
								<view style="color: #39b54a;font-size: 13px;">已验数：{{approved}}</view> -->
								<view style="color: #000;font-size: 14px;">商品数量：<span style="color: #39b54a;">{{Goodnum}}</span></view>
								<view style="color: #000;font-size: 14px;">商品金额：<span style="color: red;">{{GoodPrice}}</span></view>
							</view>
<!-- 							<view class="cu-form-group" style="justify-content: space-around;">
								<view style="color: #39b54a;font-size: 13px;">商品数量：{{Goodnum}}</view>
								<view style="color: #39b54a;font-size: 13px;">商品金额：{{GoodPrice}}</view>
							</view> -->
							</view>
						<!--商品明细列表home-->
						<!-- <view class="selectGoodsList" v-for="(item,index) in OrderGoodsList" :key="index">
							<view class="goodListItem" :class="selectLookMore == index?'goodListItem lookMore':''">
								<view class="goodsTitle">
							    <span style="float: left;">{{item.GoodsName}} </span>
								<button @tap="clickNow(index)" style="color: red;float: right;">删除</button>
								<button @tap="lookGoodsInfo(index)" style="float: right;">查看更多</button>
								</view>
								<view @tap="clickEnd(index)" >
									<view style="padding: 5px;height: 220upx;">
										<img class="list_img" @tap.stop="ViewImage('http://192.168.1.51:9000/picture'+item.Goods_Image_Path1)" v-if="item.Goods_Image_Path1!=''&&item.Goods_Image_Path1!=undefined" :src="'http://192.168.1.51:9000/picture'+item.Goods_Image_Path1" alt="">
										<img class="list_img" @tap.stop="ViewImage('../../static/image/unUplad.png')"  v-else src="../../static/image/unUplad.png" alt="">
										<view class="goods_font" >编号:{{item.GoodsCode}}</view>
										<view class="goods_font">单价:{{item.Price}}</view>
										<view class="goods_font"> 数量:{{item.Qty}}
										<span style="margin-left: 15px;">已经录入数量:{{item.Tax}}</span></view>
										<view class="goods_font"> 库存:{{item.stockqty}}
										<span style="margin-left: 15px;">金额:{{item.Amount}}</span></view>
									</view>
									<view class="goods-itemWrap">
										<text class="good-item">单位:{{item.UnitName}}</text>
										<text class="good-item" style="flex: 2;padding-left: 5px;">税率:{{item.Tax}}</text>
									</view>
									<view class="goods-itemWrap">
										<text class="good-item">折扣价:{{item.Discount}}</text>
									</view>
									<view class="goods-itemWrap">
										<text class="good-item">备注:{{item.Remark}}</text>
									</view>
								</view>
							</view>
						</view> -->
						<Goodlist :Gooditem="OrderGoodsList" @remove="removeGood" @update="clickEnd"></Goodlist>
						<!--商品明细列表end-->
				</view>
				</form>
			</view>
	</view>
	</scroll-view>
	<!--搜索商品弹窗HOME-->
	<view class="cu-modal " :class="isShowScanModel?'show':''">
		<view class="cu-dialog ls-main">
			<view class="cu-bar bg-ls justify-between">
				<view class="action">
					<view class="cuIcon-info text-white" v-show="false"></view>
				</view>
				<view class="content text-white">选择商品</view>
				<view class="action" @tap="hideGoodModal">
					<text class="cuIcon-close text-white"></text>
				</view>
			</view>
			<view class="padding text-left bg-white ls-contain" style="height: 100%;">
				<scroll-view scroll-y style="height: calc(100% - 1px);">
					<!-- <view class="ls-box" @tap="choosesGoods(index)" v-for="(item,index) in scanGoodList" :key='index' :data-index="index">
					
						<view>{{item.GoodsName}}</view>
					</view> -->
					<!-- scanGoodList -->
					<view class="Good_list" v-for="(item,index) in scanGoodList" @tap="choosesGoods(index)" :key='index'  :class="isShowScanModel?'Animation_Good':''">
						<view class="Good_image">
							<img style="width: 100%;height: 100%;border-radius: 50%;"
							 :src="item.Goods_Image_Path1 != '' 
							 &&item.Goods_Image_Path1 != undefined ?'http://192.168.1.51:9000/picture'+item.Goods_Image_Path1:'../../static/image/unUplad.png'" alt="">
						</view>
						<view class="Good_title">
							<view class="Good_content">{{item.GoodsName}}</view>
							<view class="Good_subhead">{{item.BarCode}}</view>
						</view>
						<view class="Good_edit">
							<img src="../../static/image/arrowright.png" alt="">
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
   <!--搜索商品弹窗END-->
   <!--快速扫描HOME-->
   	<!-- <view class="cu-modal " :class="kuaiScanModel?'show':''">
   		<view class="cu-dialog ls-main">
   			<view class="cu-bar bg-ls justify-between">
   				<view class="action">
   					<view class="cuIcon-info text-white" v-show="false"></view>
   				</view>
   				<view class="content text-white">选择商品</view>
   				<view class="action" @tap="hideGoodModal">
   					<text class="cuIcon-close text-white"></text>
   				</view>
   			</view>
   			<view class="padding text-left bg-white ls-contain" style="height: 100%;">
   				<scroll-view scroll-y style="height: calc(100% - 1px);">
   					
   					<view class="Good_list" v-for="(item,index) in scanGoodList" @tap="choosesGoods(index)" :key='index'  :class="isShowScanModel?'Animation_Good':''">
   						<view class="Good_image">
   							<img style="width: 100%;height: 100%;border-radius: 50%;"
   							 :src="item.Goods_Image_Path1 != '' 
   							 &&item.Goods_Image_Path1 != undefined ?'http://192.168.1.51:9000/picture'+item.Goods_Image_Path1:'../../static/image/unUplad.png'" alt="">
   						</view>
   						<view class="Good_title">
   							<view class="Good_content">{{item.GoodsName}}</view>
   							<view class="Good_subhead">{{item.BarCode}}</view>
   						</view>
   						<view class="Good_edit">
   							<img src="../../static/image/arrowright.png" alt="">
   						</view>
   					</view>
   				</scroll-view>
   			</view>
   		</view>
   	</view> -->
   <!--快速扫描END-->
   
   <!-- 旧版日期选择器 -->
	<!-- <uni-calendar ref="calendar" :insert="false" @confirm="confirm" /> -->
	<!-- 新版日期选择器 -->
	<QSpicker title="请选择日期时间" mode="bottom" type="date" ref="QS_Picekr_date" pickerId="date_1" :dataSet="dateSet"
	 showReset :autoHide="false" contentColor="#33cc33" :lineHeight=".05" @hideQSPicker="hideQSPicker($event)"
	 @showQSPicker="showQSPicker($event)" @confirm="newconfirm($event)" />

	<!-- 弹出框HOME -->
	<view class="cu-modal cu_none " :class="modalName=='Modal'?'show':''">
		<view class="cu-dialog"  :class="[{'new-cu-dialog':listshow == 4}]" >
			<view class="cu-bar bg-white justify-end">
				<view class="content">选择{{listcode}}</view>
				<view class="action" @tap="hideModal">
					<text class="cuIcon-close text-red"></text>
				</view>
			</view>
			<view style="padding: 5px 21px;">
			<view class="search" v-show="listshow == 1"><input class="inpt" @input="monitorClient" 
			 v-model="selectCli" placeholder="查询供应商" name="input"></input>
			<span class="search_span" @tap="selectClient()">搜索</span>
			</view>
			<view class="search" v-show="listshow == 2"><input class="inpt" @input="monitorStore" 
			 v-model="selectwar" placeholder="查询仓库" name="input"></input>
			<span class="search_span"  @tap="selectwarehouse()">搜索</span>
			</view>
			<view class="search" v-show="listshow == 3"><input class="inpt" @input="monitorEmp" 
			 v-model="selectsal" placeholder="查询业务员" name="input"></input>
			<span class="search_span" @tap="selectsalesmant()">搜索</span>
			</view>
			</view>
			<scroll-view style="height: 77%;" scroll-y="true">
				
			<view class="padding-xl" v-show="listshow == 1">
			<!-- 	<view class="search" ><input class="inpt" v-model="selectCli" placeholder="查询客户" name="input"></input>
				<span class="search_span" @tap="selectClient()">搜索</span>
				</view> -->
				<view>
					<!-- this.checkdata["ClientID"] = this.ClientList[e]["ClientID"]
					this.checkdata["BName"] = this.ClientList[e]["ClientName"] -->
					<view class="btn_list" v-show="checkdata.ClientID&&checkdata.BName">{{checkdata.BName}}</view>	
					<view class="btn_list" :class="[{'background_color':checkdata.ClientID&&checkdata.BName}]"  v-for="(item,index) in ClientList" 
					 @tap="checkuser(index)" :key="item.id">{{item.ClientName}}</view>
					<!-- <view class="btn_list">我是选中的供应商</view>	  -->
				</view>
			</view>
			
			<view class="padding-xl" v-show="listshow == 2">
				<view>
					<view class="btn_list"  v-for="(item,index) in StoreList" 
					 @tap="checkware(index)" :key="item.id">{{item.StoreName}}</view>			
				</view>
			</view>
			<view class="padding-xl" v-show="listshow == 3">
				<view>
					<view class="btn_list"  v-for="(item,index) in OperatorList" 
					 @tap="checksale(index)" :key="item.id">{{item.OperatorName}}</view>			
				</view>
			</view>
			</scroll-view>
		</view>
	</view>
	<!-- 弹出框END -->
	<!-- 侧边抽屉home -->
	<Drawerui Billtype="v0_setting" ref="Drawer" @RemotePrint="RemotePrint" ></Drawerui>
	<!-- 侧边抽屉end -->
	</view>
</template>
<script>
	import allConst from "@/Json.js"
	import uniIcons from '@/components/uni-icon/uni-icon.vue';
	// import uniCalendar from '@/components/uni-calendar/uni-calendar.vue';
	// import * as Api from '@/syApis/syAddOrder/syaddApis.js';
	// import * as GetApi from '@/syApis/syBb/apis.js';
	import * as GetApi from '@/syApis/syHttp/Http.js';
	import Drawerui from '@/components/Drawer.vue';
	import QSpicker from '@/components/QuShe-picker/QuShe-picker.vue';
	import  * as rules  from "@/common/barcodeRules.js";
	import Goodlist from "@/components/selectGoodsItem/GoodList.vue";
	import * as CommonFun from "@/common/common.js";
	export default {
		// name:"uniIcons",
		data() {
			return {
				date: '',
				isshow:false,
				timeData: {
					clockinfo: '',
					date: '',
					fulldate: '',
					lunar: '',
					month: '',
					range: '',
					year: ''
				},
				modalName: '',
				BillNo: "",//单据编号
				//单据类型
				BillType: 2,
				IsAdd: 0,
				BillDate: "",
				//订单商品
				OrderGoodsList: [
					
				],
				//当前选择的商品
				NowSelectGoods: {},
				//仓库的列表
				StoreList: [],
				temStoreList: [],//临时 用于快速搜索
				//业务员的列表
				OperatorList: [],
				temOperatorList: [],//临时用于快速搜索
				//供应商的列表
				ClientList: [],
				temClientList: [],//临时用于快速搜索
				//制单人
				CreateName: uni.getStorageSync("UserName"),
				//税率
				Tax: "",
				//商品列表查看更多标识
				selectLookMore: -1,
				//按下屏幕的时间
				endTime: 0,
				//计算点击的时间
				touchTime: 0,
				//扫码多商品列表
				scanGoodList: [],
				//当前多商品选择的索引
				current: -1,
				//多规格商品弹框
				isShowScanModel: false,
				//搜索条件
				searchKey: "",
				//单据类型
				BillName: "采购订单",
				//单据类型编号
				BillTypes: 2,
				
				listcode:'',
				// 选中的供应商
				checkedClientList:[],
				//选中的仓库
				checkedwarehouse:[],
				//选中的业务员
				checksalesman:[],
				// 搜索供应商
				selectCli:'',
				// 搜索的仓库
				selectwar:'',
				// 搜索的业务员
				selectsal:'',
				diy_layer:false,//自定义弹窗显示
				listshow:-1,
				// 页面的数据(包括从其他页面返回的)
				// console.log(that.checkdata.ClientID)
				// console.log(that.checkdata.BName)
				checkdata:{
					BillTime: "",
					ClientID:'',
					BName:'',
					stockName:'',
					EName:''
				},
				BillRemark:'',//备注
				isquote:-1,//用于判断是引用单据返回的还是查单返回的
				CollectAmount:'',//本次收付款
				NoSmallAmount:'',//抹零金额
				// isquote:-1,
				setfixeds:false,
				OrderGoodsListLen:'',//商品个数
				GoodPrice:0,//商品总金额
				Goodnum:0,//商品总数量
				approved:0,//已验数
				noapproved:0,//未验数
				approvedlist:[],//选中单据的商品
				more:false,
				//日期选择
				dateSet: {
					dateMode: 3,
					dateFormatArray: ['-', '-', ' ', ':', ':']
				},
				CustomBar: this.CustomBar,
				setting:{
					validation:{
						bluetooth:-1,
						long:-1,
						repetition:-1,
						// enter:-1,
						barcode:-1,
						selectd:-1,
						Openquickscan:-1,
						// IsAll:-1,
					}
				},
				//单据是否直接审核
				isBillCheckQx:false
			}
		},
		components: {
			// uniCalendar,
			uniIcons,
			QSpicker,
			Drawerui,
			Goodlist
		},  
		onLoad(options) {
			var that = this
			// setTimeout(() => {
			// 	this.showCalendar = true
			// }, 350);
			this.getClientList();//供应商
			this.GetOperatorMessage();//业务员
			this.GetStoreMessage();//仓库
			
			console.log("读取本地配置")
			console.log('异步获取配置')
			uni.getStorage({
			key:"setting",
			success(e){
			e.data
			// console.log(e.data)
			// console.log(JSON.parse(e.data))
			var valida = JSON.parse(e.data)
			// console.log(valida.validation)
			that.setting.validation = valida.validation
			
			    }
			})
			
			let SystemSettingInfo = uni.getStorageSync("SystemSettingInfo", ""); //存储系统设置
			if(SystemSettingInfo!=""){
				SystemSettingInfo = JSON.parse(SystemSettingInfo);
				SystemSettingInfo.forEach((item, index) => {
					if (item.SystemName == '单据是否直接审核') {
						if (item.Value == "1") {
							that.isBillCheckQx = true;
						}
					}
				});
			}
			
			// console.log('打印全局管理')
			// console.log(this.$store.state)
		},
		onShow(){
			this.$eventHub.$off('psfire');
			this.$eventHub.$off('deliveryoutfire');
			this.$eventHub.$off('Addfires');
			this.$eventHub.$off('fireredact');
			this.$eventHub.$off('updateGood');
			this.$eventHub.$off('clientListen');
			console.log('商品列表')
			console.log(this.OrderGoodsList)
			this.imputed()
			// 计算商品的价格
			// var tmpprice = 0;//商品总金额
			// var tmpnum =0;//商品数量
			// for(var i in this.OrderGoodsList){
			// 	tmpprice = parseFloat(tmpprice)+parseFloat(this.OrderGoodsList[i].Amount) 
			// 	tmpnum = parseFloat(tmpnum)+parseFloat(this.OrderGoodsList[i].Qty) 
			// }
			// this.GoodPrice =  tmpprice
			// this.Goodnum =  tmpnum
			// console.log('验单的价格')
			// console.log(this.GoodPrice)
			
			// // 已验单数
			// var num =0;
			// for(var j in this.OrderGoodsList){
			// 	for(var i in this.approvedlist){
			// 		if(this.approvedlist[i].GoodsID == this.OrderGoodsList[j].GoodsID){
			// 		    num = (parseFloat(num)+parseFloat(this.OrderGoodsList[j].Qty))  
			// 		}
			// 	}
			// }
			// this.approved = num;
		},
		created() {
			let date = new Date();
			console.log('时间')
			console.log(date)
			this.BillDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
		},
		// onHide() {
		// 	var data = JSON.parse(this.setting)
		// 	uni.setStorage({
		// 	key:"setting",
		// 	data:data
		// 	})
		// },
		
		onPageScroll(res){
			// console.log(res.scrollTop);//距离页面顶部距离
			var scrolls = res.scrollTop
			var that = this
			uni.getSystemInfo({
			　　success: function(res) { // res - 各种参数
			// 　　   console.log(res.windowWidth); // 屏幕的宽度 
			         // console.log('返回顶部出现的位置'+(res.screenHeight+res.screenHeight/3))
			　　    let info = uni.createSelectorQuery().select(".sticky");
			　　　  　info.boundingClientRect(function(data) { //data - 各种参数
			// 　　　  　console.log("元素的高度"+data.height)  // 获取元素宽度
			  //    console.log('滚动')
				 // console.log(info)
				 // console.log('滚动111')
				 // console.log(scrolls)
			         if(scrolls>(data.height+10)){
						 // console.log('大于了')
						 that.setfixeds = true
					 }else{
						 that.setfixeds = false
					 }
					 // that.istop = scrolls>(res.screenHeight+res.screenHeight/2)?true:false
			　　    }).exec()
			       }
			});
		},

		methods: {
			// 跳转到引用上级单据
			quotes:function(){
				var that = this
				this.$eventHub.$on('deliveryoutfire', function (data) {
					//console.log('返回成功的参数')
					var dataarray = data;
					that.OrderGoodsList = [];
					that.checkdata = []
					that.BillRemark = ''
					that.CollectAmount = ''
					that.NoSmallAmount = ''
					console.log('-------我是引用上级单据返回的--------')
					console.log(dataarray)
					dataarray["BillTime"] = that.timesubstr(dataarray["BillTime"])
					that.checkdata = dataarray
					//console.log(dataarray.SourceBillName)
					that.isquote = 1;
					that.BillNo = dataarray.BillNo;//单据编号
					if(that.isquote == 1){
						that.details(that.checkdata.BillID)
					}else if(that.isquote == 2){
						that.selectbill(that.checkdata.BillID)
					}
					that.$eventHub.$off('deliveryoutfire'); 
					});
				uni.navigateTo({
				    url: '../validation/quote/quote'
				});
			},
			//查看源单明细
			selectsource:function(){
				if(this.isquote == -1){
					// GetApi.showTip("请选择单据");
					uni.showToast({
						title:'请选择单据!',
						icon:'none',
						position:'center'
					})
					return
				} 
				console.log('跳转页面携带的参数')
				console.log(this.OrderGoodsList)
				uni.navigateTo({
					url: '../validation/selectsource/selectsource?id='+this.checkdata.BillID+'&BillNo='+this.checkdata.BillNo
					+'&OrderGoodsList='+JSON.stringify(this.OrderGoodsList)+"&isquote="+this.isquote
					// JSON.stringify()
				    
				});
			},
			//跳转到查单界面
			selectorder:function(){
				var that = this
				this.$eventHub.$on('psfire', function (data) {
					//console.log('返回成功的参数')
					var dataarray = data
					that.OrderGoodsList = []
					that.checkdata = []
					that.BillRemark = ''
					that.CollectAmount = ''
					that.NoSmallAmount = ''
					console.log('-------我是查单返回的--------')
					console.log(dataarray)
					dataarray["BillTime"] = that.timesubstr(dataarray["BillTime"]);
					that.checkdata = dataarray;
					that.BillRemark = dataarray.Comment 
					that.isquote = 2;
					//console.log(dataarray.SourceBillName)
					that.BillNo = dataarray.BillNo;//单据编号
					if(that.isquote == 1){
						that.details(that.checkdata.BillID)
					}else if(that.isquote == 2){
						that.selectbill(that.checkdata.BillID)
					}
					that.$eventHub.$off('psfire');
					});
				uni.navigateTo({
				    url: '../validation/selPurchase/selPurchase'
				});
			},
			//跳转选择供应商界面
			clicktoclient:function(){
				var that = this
				this.$eventHub.$on('clientListen', function (data) {
			          console.log('返回的参数')
					  // JSON.parse(data)
					  var checkd = JSON.parse(data)
					  that.checkdata.ClientID = checkd["ClientID"]
					  that.checkdata.BName = checkd["ClientName"]
					  console.log(JSON.parse(data))
					  console.log(that.checkdata.ClientID)
					  console.log(that.checkdata.BName)
					  
					that.$eventHub.$off('clientListen');
					});
				uni.navigateTo({
					// pages/clientSelect/clientSelect
				    url: '../clientSelect/clientSelect?isClient=1'
				});
			},
			//清空
			ckechdempty:function(nav){
				if(nav == 1){
					this.checkdata.ClientID = "";
					this.checkdata.BName = "";
				}else if(nav == 2){
					console.log('执行了')
					console.log(this.checkdata.StoreID)
					console.log(this.checkdata.stockName)
					
					this.checkdata.StoreID = "";
					this.checkdata.stockName = "";
					console.log(this.checkdata.stockName)
					console.log(this.checkdata.StoreID)
				}else if(nav == 3){
					this.checkdata.EmpID = "";
					this.checkdata.EName = "";
				}
			},
			//统计数量和计算价格
			imputed:function(){
				var tmpprice = 0;//商品总金额
				var tmpnum =0;//商品数量
				for(var i in this.OrderGoodsList){
					tmpprice = parseFloat(tmpprice)+parseFloat(this.OrderGoodsList[i].Amount) 
					tmpnum = parseFloat(tmpnum)+parseFloat(this.OrderGoodsList[i].Qty) 
				}
				this.GoodPrice =  parseFloat(tmpprice).toFixed(2)
				this.Goodnum =  tmpnum
				console.log('验单的价格')
				console.log(this.GoodPrice)
				
				// 已验单数
				var num =0;
				for(var j in this.OrderGoodsList){
					for(var i in this.approvedlist){
						if(this.approvedlist[i].GoodsID == this.OrderGoodsList[j].GoodsID){
						    num = (parseFloat(num)+parseFloat(this.OrderGoodsList[j].Qty))  
						}
					}
				}
				this.approved = num;
			},
			//查看图片
			ViewImage:function(e){
				console.log(e)
				uni.previewImage({
					current: e,
					urls:[e] 
				});
			},
			//设置 选中
			clickcheckd(e){
				this.setting.validation[e.target.dataset.target] = this.setting.validation[e.target.dataset.target] == e.target.dataset.index?-1:e.target.dataset.index
				var data = JSON.stringify(this.setting)
				uni.setStorage({
				key:"setting",
				data:data
				})
			},
			// 远程打印
			RemotePrint(e){
				console.log('点击了远程打印')
				console.log(e)
				console.log(this.checkdata)
				var data = {};
				var Save_M_Data_Json = {};
				Save_M_Data_Json = {
					Order_Number: this.checkdata.BillNo,
					BillName: '采购入库单',
					Printer: this.CreateName,
					BillID: this.checkdata.BillID,
					PrintNum: e.detail.printNum + "",
					PrintPCNumber: e.detail.checkd + ""
				};
				data = {
					Save_M_Data_Json: JSON.stringify(Save_M_Data_Json)
				}
				var that = this
				GetApi.Add_Android_Print(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {
							GetApi.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							GetApi.showTip(res.data.ErrorMsg);
						} else {
							GetApi.showTip("打印成功");
							var config = that.GetConfig()
							console.log(config)
							console.log(config.long)
							//等于0表示  ----打印后询问是否审核单据
							if(config.long == 0){
								GetApi.showConfirm("是否审核单据", function(result) {
									if (result) {
										that.toBillCheck();
									}
								})
							}else{
								that.toBillCheck()
							}
						}
					}
				})
			},
			//审核单据
			toBillCheck(BillID) {
				var that = this;
				let data = {
					BillType: '2',
					BillID: BillID || this.checkdata.BillID,
					BillName: '采购入库单'
				};
				console.log(this.checkdata)
				GetApi.Bill_Check(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {
							GetApi.showTip("登录超时!");
						} else if (res.data.ErrorMsg != "") {
							
							var str = res.data.ErrorMsg
							var newstr = str.replace('mssql:','')  
							GetApi.showTip(newstr);
						} else {
							// that.isBillCheckSuc[that.isBillCheck] = checkCountList[that.isBillCheck];
							// that.isBillCheck++;
							GetApi.showTip("审核成功");
							if(that.isquote == 1){
								that.details(that.checkdata.BillID)
							}else{
								that.selectbill(that.checkdata.BillID)
							}
						}
					} else {
			
					}
					//关闭弹出框
					that.$refs.Drawer.cancelModel()
					that.$refs.Drawer.hideModal()
					// that.toBillCheck(checkCountList, index, countSize);
				})
			},
			// 读取设置配置信息
			GetConfig(){
				return JSON.parse(uni.getStorageSync("v0_setting",""))
				},
			//显示选择日期界面
			changeShow(name, type) {
				this.startAndEndTime = type;
				this.$refs[name].show();
				this.dateName = name;
			},
			showQSPicker(res) {
				console.log(res);
			},
			hideQSPicker(res) {
			
			},
			newconfirm(res) {
				// if (this.startAndEndTime == 0) {
				// 	this.startTime = res.data;
				// } else {
				// 	this.endTime = res.data;
				// }
				var data = GetApi.splitdate(res.data);//处理的日期
				console.log("处理的日期")
				console.log(data)
				// var fulldata = res.data
				this.checkdata.BillTime = data
				console.log(res)
				this.$refs[this.dateName].hide();
			},
			//关闭弹窗
			closemodel:function(){
				this.isshow = false
			},
			//监听供应商
			monitorClient(evt){
				// console.log(evt.detail.value)
				var val = evt.detail.value;//取到监听的值
				var resarr = []
				// ClientName
				if(val !=""){
					for(var i in this.ClientList){
						var string1 = this.ClientList[i].ClientName
						// console.log(string1.indexOf(val))
						// var string2 = this.ClientList[i].Address
						// if(string1.valueOf(val) >=0 ||string2.valueOf(val)>=0){
						if(string1.indexOf(val) >=0){
							resarr.push(this.ClientList[i])
						}
					}
					
					if(resarr.length == 0){
						GetApi.showTip("查无数据");
					}else{
						this.ClientList = resarr
					}
				}else{
					this.ClientList = this.temClientList
				}
				
			},
			//监听仓库
			monitorStore(evt){
				var val = evt.detail.value;//取到监听的值
				console.log(val)
				var resarr = []
				// ClientName
				if(val !=""){
					for(var i in this.StoreList){
						var string1 = this.StoreList[i].StoreName
						var string2 = this.StoreList[i].BranchName
						// console.log(string1.indexOf(val))
						// var string2 = this.ClientList[i].Address
						// if(string1.valueOf(val) >=0 ||string2.valueOf(val)>=0){
						if(string1.indexOf(val) >=0 ||string2.indexOf(val) >=0){
							resarr.push(this.StoreList[i])
						}
					}
					if(resarr.length == 0){
						GetApi.showTip("查无数据");
						this.StoreList = []
					}else{
						this.StoreList = resarr
					}
					// this. = resarr
				}else{
					this.StoreList = this.temStoreList
				}
			},
			//监听业务员
			monitorEmp(evt){
				
				var val = evt.detail.value;//取到监听的值
				console.log(val)
				console.log(this.OperatorList)
				var resarr = []
				// ClientName
				if(val !=""){
					for(var i in this.OperatorList){
						
						console.log(this.OperatorList[i])
						var string1 = this.OperatorList[i].OperatorName
						var string2 = this.OperatorList[i].Address
						// console.log(string1.indexOf(val))
						// var string2 = this.ClientList[i].Address
						// if(string1.valueOf(val) >=0 ||string2.valueOf(val)>=0){
						if(string1.indexOf(val) >=0 ||string2.indexOf(val) >=0){
							resarr.push(this.OperatorList[i])
						}
						if(resarr == ""){
							GetApi.showTip("查无数据");
							this.OperatorList = []
						}else{
							this.OperatorList = resarr
						}
					}
					// this.OperatorList = resarr
				}else{
					this.OperatorList = this.temOperatorList
				}
			},
			
			// 搜索的供应商
			selectClient:function(){
				//console.log(this.selectCli)
				this.getClientList(this.selectCli)
				
			},
			// 搜索的仓库
			selectwarehouse:function(){
				//console.log(this.selectwar)
				this.GetStoreMessage(this.selectwar)
			},
			// 搜索的业务员
			selectsalesmant:function(){
				//console.log(this.selectsal)
				this.GetOperatorMessage(this.selectsal)
			},

			// 选中的供应商
			checkuser:function(e){
				// this.checkedClientList = this.ClientList[e]["ClientID"]
				// ClientName
				this.checkdata["ClientID"] = this.ClientList[e]["ClientID"]
				this.checkdata["BName"] = this.ClientList[e]["ClientName"]
				
				// this.checklist = e
				this.modalName =null
				//console.log('打印的参数')
				//console.log(this.checkdata)
			},
			// 选中的仓库
			checkware:function(e){
				this.modalName =null
				// this.checkedwarehouse = this.StoreList[e]
				// 仓库StoreID stockName
				// this.checklist = e
				this.checkdata["StoreID"] = this.StoreList[e]["StoreID"]
				this.checkdata["stockName"] = this.StoreList[e]["StoreName"]
				// this.isshow=false
				//console.log('打印的参数')
				//console.log(this.checkdata)
			},
			// 选中的业务员
			checksale:function(e){
				this.modalName =null
				// 业务员 EmpID EName
				// this.checksalesman = this.OperatorList[e]
				this.checkdata["EmpID"] = this.OperatorList[e]["OperatorID"]
				this.checkdata["EName"] = this.OperatorList[e]["OperatorName"]
				this.isshow=false
				//console.log('打印的参数')
				//console.log(this.checksalesman)
			},

			choosesGoods(index) {
				var that = this
				if(this.checkdata.StoreID ==""||this.checkdata.StoreID ==undefined){
					GetApi.showTip('请先建立单据!')
					return
				}
				// that.OrderGoodsList.push(that.scanGoodList[index]);
				this.isShowScanModel = false;
				console.log(that.scanGoodList[index]);
				that.scanGoodList[index]["stockName"] = this.checkdata.stockName;//赋值表头仓库
				that.scanGoodList[index]["StoreID"] = this.checkdata.StoreID;//赋值表头仓库
				that.toredact(that.scanGoodList[index])
			},
			// 搜索选择商品后跳转编辑页面 ----然后添加
			toredact(event){
				// console.log(event)
				// return
				var that = this;
				var toevent = event
				this.$eventHub.$on('fireredact', function(data) {
					// that.OrderGoodsList[data.index] = JSON.parse(data.NewGoodInfo);
					// that.selectLookMore = -1;
					// that.OrderGoodsList.push(JSON.parse(data))
					that.GoodsEach(JSON.parse(data));
					console.log(data);
					console.log('返回成功的参数');
					that.$eventHub.$off('fireredact');
				});
				var batchs = null
				if(this.isquote == 1){
					batchs = 1
				}
				uni.setStorageSync("source",JSON.stringify(this.approvedlist))
				uni.setStorageSync("Order",JSON.stringify(this.OrderGoodsList))
				uni.navigateTo({
					// url: "../SelectedGoods/SelectedGoods?StoreID=" + this.checkdata.StoreID+"&name=采购入库单"+"&BillID="+this.checkdata.BillID+
					// "&stockName="+this.checkdata.stockName
					url: "../SelectedGoods/Goodredact?goodData=" + JSON.stringify(toevent)+"&name=采购入库单"
					+"&ClientID="+this.checkdata.ClientID+"&StoreID=" + this.checkdata.StoreID
					// +"&source="+JSON.stringify(this.approvedlist)
					+"&batch="+batchs
					// +"&Order="+JSON.stringify(this.OrderGoodsList)
					+"&isquote="+this.isquote
				});
			},
			//添加商品
			GoodsEach(Goods){
				var that = this
				var order = that.OrderGoodsList
				console.log('添加的商品')
				console.log(Goods)
				console.log('存在的商品')
				console.log(order)
				var batch = false
				if(this.isquote == 1){
					batch = true
				}
				var result = CommonFun.equality(order,Goods,batch)
				console.log('验单结果--------------------------')
				console.log(result)
				if(result.status == true){
					var index = result.index
					//需要单独赋值
					that.OrderGoodsList[index]["StoreID"] = Goods["StoreID"] //仓库
					that.OrderGoodsList[index]["stockName"] = Goods["stockName"] //仓库名称
					that.OrderGoodsList[index]["UnitID"] = Goods["UnitID"] //单位
					that.OrderGoodsList[index]["IsGift"] = Goods["IsGift"]  //赠品
					that.OrderGoodsList[index]["BatchNo"] = Goods["BatchNo"] //批号
					that.OrderGoodsList[index]["ProductionDate"] = Goods["ProductionDate"] //生产日期
					that.OrderGoodsList[index]["validityDate"] = Goods["validityDate"]//到期日期
					that.OrderGoodsList[index]["Tax"] = Goods["Tax"]  //税率
					that.OrderGoodsList[index]["Price"] = parseFloat(Goods["Price"]) //单价
					that.OrderGoodsList[index]["Discount"] = Goods["Discount"]//折扣
					that.OrderGoodsList[index]["Qty"] =  (parseFloat(that.OrderGoodsList[index]["Qty"])+parseFloat(Goods["Qty"]))  //数量
					that.OrderGoodsList[index]["Remark"] = Goods["Remark"] //数量
					that.OrderGoodsList[index]["Amount"] = parseFloat(parseFloat(that.OrderGoodsList[index]["Amount"])+parseFloat(Goods["Amount"])).toFixed(2)  //金额
				}else{
					that.OrderGoodsList.push(Goods)
				}
				that.source_Good()
			},
			search() {
				// console.log('点击看')
				// return
				if (this.checkdata.StoreID == ""||this.checkdata.StoreID==undefined) {
					uni.showToast({
						title: "请先选择仓库或建立单据",
						icon:'none'
					});
					return;
				};
				if(this.isShowScanModel == true){
					console.log('打印----')
					return
				}
				this.GetBarcodeGoodsMessageModel(this.searchKey);
			},
			//扫码获取商品
			tel: function() {
				// if (this.checkdata.StoreID == ""||this.checkdata.StoreID==undefined) {
				// 	uni.showToast({
				// 		title: "请先选择仓库或建立单据",
				// 		icon:'none'
				// 	});
				// 	return;
				// };
				this.current = -1;
				// 调起条码扫描
				var that = this;
				uni.scanCode({
					scanType: 'barCode',
					success: function(res) {
						that.GetBarcodeGoodsMessageModel(res.result);
						//console.log('条码类型：' + res.scanType);
						//console.log('条码内容：' + res.result);
					},
					fail(e) {
						//console.log(e);
					}
				});
			},
			//通过条码扫描商品
			GetBarcodeGoodsMessageModel(barcode) {
				let Model = "";
				// var config = JSON.parse(uni.getStorageSync("v0_setting"))
				
				var config = this.GetConfig()
				var bar = JSON.parse(uni.getStorageSync("BarCode",""))
				console.log('配置信息')
				console.log(config.barcode)
				// 0代表启用条码规则
				if(config.barcode == 0){
					var code = rules.getRulesStr(true,bar,barcode)
					console.log('-----------')
					console.log(code)
					barcode = code.searchKey
				}
				// selectd
				// return
				if(config.selectd ==1){
					Model = "%like"
				}else if(config.selectd ==2){
					Model = "like%"
				}else{
					Model = "like"
				}
				let data = {
					// this.BillName
					BillName: "采购入库单",
					BarCode: barcode,
					Model: Model+""
				};
				var that = this;
				GetApi.GetBarcodeGoodsMessageModel(data, function(res) {
					//console.log(res.data.ResultMsg);
					// Api.showTip(res.data.ResultMsg);
					if (res.data.ResultMsg != '') {
						if (res.data.ResultMsg.length == 0) {
							GetApi.showTip("查无数据");
							// that.isShowScanModel = true;
							return
						}
						var GoodList = res.data.ResultMsg;
						// console.log('扫码成功!')
						// console.log(GoodList)
						// console.log(GoodList[0])
						// console.log(GoodList)
						// return
						for(var i in GoodList){
							GoodList[i].urate = GoodList[i].URate || GoodList[i].urate
						}
						if(config.Openquickscan == 0){
							if(GoodList[0].IsBatch == true){
								GetApi.showTip("批号商品不允许快速扫描!");
							}else{
								that.prices(GoodList[0])
							}
							
						}else{
							if(GoodList.length > 1){
								that.isShowScanModel = true;
								that.scanGoodList = GoodList
							}else{
								that.scanGoodList = GoodList
								that.choosesGoods(0)
							}
							
						}
						
						console.log(that.scanGoodList)
						that.searchKey = ''
						//console.log("Ji");
					} else if (res.data.ResultMsg == "") {
						that.searchKey = ''
						GetApi.showTip("查无数据");
					} else if (res.data.ErrorMsg == "获取登录信息失败") {
                                console.log('获取登录信息失败!')
					} else {

					}

				})
			},
			removeGood(e){
				var del = this.OrderGoodsList
				del.splice(e.index,1)
				this.OrderGoodsList = del
				this.imputed()
			},
			//编辑商品
			clickEnd:function(e) {
				var that = this;
				this.$eventHub.$on('updateGood', function(data) {
					console.log('返回成功的参数')
					console.log(data.index)
					var Goodjson  = JSON.parse(data.NewGoodInfo);//返回的对象
                    that.forupdate(Goodjson,data.index)
					that.$eventHub.$off('updateGood');
				});
				this.OrderGoodsList[e.index]["ClientID"] = this.checkdata.ClientID;
				var batchs = null
				if(this.isquote == 1){
					batchs = 1
				}
				uni.navigateTo({
					url: "../SelectedGoods/selectGoodInfo?goodData=" + JSON.stringify(this.OrderGoodsList[e.index])
					 + "&selectIndex=" +e.index+ "&Bname=采购入库单"+"&source="+JSON.stringify(this.approvedlist)
					 +"&batch="+batchs
					 
				});
			},
			// 需要单独赋值
			forupdate:function(item,index){
				this.OrderGoodsList[index].StoreID = item.StoreID;
				this.OrderGoodsList[index].stockName = item.stockName;
				this.OrderGoodsList[index].UnitID = item.UnitID;
				this.OrderGoodsList[index].IsGift = item.IsGift;
				this.OrderGoodsList[index].BatchNo = item.BatchNo;
				this.OrderGoodsList[index].ProductionDate = item.ProductionDate;
				this.OrderGoodsList[index].validityDate = item.validityDate;
				this.OrderGoodsList[index].Tax = item.Tax;
				this.OrderGoodsList[index].Price = parseFloat(item.Price);
				this.OrderGoodsList[index].Discount = item.Discount;
				this.OrderGoodsList[index].Qty = parseFloat(item.Qty);//数量修改
				this.OrderGoodsList[index].Remark = item.Remark;
				this.OrderGoodsList[index].Amount = parseFloat(item.Amount).toFixed(2);
				this.source_Good();
			},
			//获取更多商品信息
			lookGoodsInfo(index) {
				if (this.selectLookMore == index) {
					this.selectLookMore = -1;
				} else {
					this.selectLookMore = index;
				}
			},
			//获取供应商列表
			getClientList:function(e) {
				let data = {};
				// 当e不为空时,为搜索
				if(e =="" || e == undefined){
					data = {
						Filter: "IsClient<>1"
					}
				}else{
					this.checkedClientList=[]
					data = {
						// "(ClientName●like●'%" + cc + "%')"ClientCode
						Filter: "IsClient<>1"+" and " +"("+"ClientName●like●'%"+e+"%'" +" or "+"ClientCode●like●'%"+e+"%'"+")"
					}
				}
				var that = this;
				GetApi.GetClientPurMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							GetApi.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							GetApi.showTip(res.data.ErrorMsg);
						} else if(res.data.ResultMsg != "" && res.data.TipsMsg=="OK"){
							//console.log('不为空')
							that.ClientList = res.data.ResultMsg;
							that.temClientList = res.data.ResultMsg;
							
						}else {
							//console.log('为空')
							that.ClientList = []
							that.diy_layer = true
							    setTimeout(function () {
							        that.diy_layer =false
							}, 1600)
							// uni.showToast({
							// 	icon: 'none',
							// 	position: 'bottom',
							// 	title: "查无数据"
							// });
							// Api.showTip("查无数据");
						}
					} else {
                        GetApi.showTip("服务器错误!");
					}
				});
			},
			//获取业务员列表
			GetOperatorMessage:function(e) {
				let data = {};
				// 当e不为空时,为搜索
				if(e =="" || e == undefined){
					data = {
						Filter: ""
					}
				}else{
					this.OperatorList=[]
					data = {
						// "(ClientName●like●'%" + cc + "%')"ClientCode
						Filter: "("+"OperatorName●like●'%"+e+"%'" +" or "+"OperatorCode●like●'%"+e+"%'"+")"
					}
				}
				var that = this;
				GetApi.GetOperatorMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							GetApi.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							GetApi.showTip(res.data.ErrorMsg);
						}else if(res.data.ResultMsg != "" && res.data.TipsMsg=="OK"){
							that.OperatorList = res.data.ResultMsg;
							that.temOperatorList = res.data.ResultMsg;
						}else {
							that.OperatorList = []
							that.diy_layer = true
							    setTimeout(function () {
							        that.diy_layer =false
							}, 1600)
						}		
					} else {
						GetApi.showTip("服务器错误!");
					}
				});
			},
			//获取仓库
			GetStoreMessage:function(e) {
				let data = {};
				// 当e不为空时,为搜索
				if(e =="" || e == undefined){
					data = {
						Filter: ""
					}
				}else{
					this.OperatorList=[]
					data = {
						// "(ClientName●like●'%" + cc + "%')"ClientCode
						Filter: "("+"StoreName●like●'%"+e+"%'" +" or "+"BranchName●like●'%"+e+"%'"+")"
					}
				}
				var that = this;
				GetApi.GetStoreMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							GetApi.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							GetApi.showTip(res.data.ErrorMsg);
						}else if(res.data.ResultMsg != "" && res.data.TipsMsg=="OK"){
							that.StoreList = res.data.ResultMsg;
							that.temStoreList = res.data.ResultMsg;
						} else {
							that.StoreList = []
							that.diy_layer = true
							    setTimeout(function () {
							        that.diy_layer =false
							}, 1600)
						}
					} else {
							GetApi.showTip("服务器错误!");
					}
				});
			},
            clickopen:function(evt,msg){
            	var that = this;	
            	console.log(evt)
            	this.listshow = Number(evt);
            	that.listcode = msg;
            	that.modalName = 'Modal'
            },
			open() {
				this.$refs.calendar.open();
			},
			confirm(e) {
				// var fulldate = e.detail.fulldate
				// //console.log(e.detail.fulldate);
			   var that = this
			   var fulldata = e.fulldate
			   that.checkdata.BillTime = fulldata
			   // that.checkdata = Object.assign(that.checkdata);
				//console.log(this.checkdata.BillTime)
			},
			//添加商品
			AddGood() {
				if (this.checkdata.StoreID == ""||this.checkdata.StoreID==undefined) {
					uni.showToast({
						title: "请先选择仓库或建立单据",
						icon:'none'
					});
					return;
				};
				if(this.checkdata.BName == ''){
					uni.showToast({
						title: "请先选择供应商",
						icon:'none'
					});
					return;
				}
				// console.log('点击了添加商品')
				// console.log(this.checkdata)
				// return
				var that = this;
				this.$eventHub.$on('Addfires', function(data) {
					// var NewGoodListTemp = that.OrderGoodsList;
					var GoodsItem = JSON.parse(data);
					console.log('添加商品成功后返回的')
					console.log(GoodsItem)
					// console.log(data)
					that.GoodsEach(GoodsItem)
					// that.OrderGoodsList = NewGoodListTemp;
					// console.log(that.OrderGoodsList)
					that.OrderGoodsListLen = that.OrderGoodsList.length
					that.$eventHub.$off('Addfires');//取消监听防止资源浪费
				});
				/*
				  StoreID  仓库id
				  name 订单类型
				  stockName 仓库名称
				  Detail 源单
				  ClientID 供应商
				*/
			    var batchs = null
			    if(this.isquote == 1){
					batchs = 1
				}else{
					this.checkdata.Qty = this.checkdata.UNQTY
				}
				uni.setStorageSync("Detail",JSON.stringify(this.approvedlist))
				uni.setStorageSync("Order",JSON.stringify(this.OrderGoodsList))
				uni.navigateTo({
					url: "../SelectedGoods/SelectedGoods?StoreID=" + this.checkdata.StoreID+"&name=采购入库单"+
					"&stockName="+this.checkdata.stockName
					// +"&Detail="+JSON.stringify(this.approvedlist)
					+"&ClientID="+this.checkdata.ClientID+"&batch="+batchs
					// +"&Order="+JSON.stringify(this.OrderGoodsList)
					+"&isquote="+this.isquote
					
				});
			},
			showModal(e) {
				//console.log(1111)
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal() {
				//console.log(222)
				this.modalName = null
			},
			//关闭  选择商品  弹出层
			hideGoodModal(){
				this.isShowScanModel = null
			},
			
			//保存单据
			AddBillOrder() {
				var that = this;
				console.log('点击了保存单据------');
				if (that.checkdata.BillNo == "" || that.checkdata.BillNo == undefined) {
					GetApi.showTip("单号不能为空");
					return
				} else if (that.checkdata.BillTime == ""||that.checkdata.BillTime == undefined) {
					GetApi.showTip("开单时间不能为空");
					return
				}else if(that.checkdata.ClientID==""||that.checkdata.ClientID==undefined){
					GetApi.showTip("供应商不能为空");
					return
				}else if(that.checkdata.StoreID==""||that.checkdata.StoreID ==undefined){
					GetApi.showTip("仓库不能为空");
					return
				}else if(that.checkdata.EmpID==""||that.checkdata.EmpID == undefined){
					GetApi.showTip("业务员不能为空");
					return
				} else {
					let ClientID = uni.getStorageSync("UserCode");
					let CreateName = uni.getStorageSync("UserName");
					// var SillType = null
					// if(that.isquote == 1){
					// 	SillType = 1
					// }else{
					// 	SillType = that.checkdata.SourceBillType
					// }
					var SillType = that.isquote == 1?1:that.checkdata.SourceBillType
					var Comment = that.BillRemark == ''||that.BillRemark==undefined?'':that.BillRemark
					let CreateID = uni.getStorageSync("UserCode");
					let Save_M_Data_Json = {
						BillNo: that.checkdata.BillNo+"",
						BillTime: GetApi.splitdate(that.checkdata.BillTime) +"",
						ClientID: that.checkdata.ClientID+"",
						StoreID: that.checkdata.StoreID+"",
						StoreID2:'0',
						EmpID: that.checkdata.EmpID+"",
						BankID:"0",
						VIPID:"0",
						Amount:that.GoodPrice+"",
						CollectAmount:that.CollectAmount+"",
						NoSmallAmount:that.NoSmallAmount+"",
						CreateID: CreateID+"",
						CreateName: CreateName+"",
						Comment: Comment+"",
						SourceBillType:SillType+"",
						PayMode:"0",
						Int1:"0",
						String1:"0",
					};
					console.log('这是Save_M_Data_Json打印的参数')
					console.log(Save_M_Data_Json)
					// return
					var Save_D_Data_Json = [];
					this.OrderGoodsList.forEach((item, index) => {
						console.log('打印forEach的内容')
						console.log(item)
						let itemData = {
							BillType:"2",
							GoodsID: item.GoodsID+"",
							UnitID: item.UnitID+"",
							URate: item.urate+"",
							Discount: item.Discount + "",
							Tax: item.Tax+"",
							Qty: item.Qty + "",
							Price: item.Price + "",
							Amount: item.Amount + "",
							BatchNo:(item.BatchNo== undefined?'':item.BatchNo)+"",
							Remark: item.Remark==""||item.Remark==undefined?"0":(item.Remark+""),
							Int1:"0",
							String3: item.BarCode+"",
							StoreID: item.StoreID+"",
							StoreID2:"",
							SourceBillType:(item.SourceBillType==undefined?'':item.SourceBillType)+"",
							SourceBillID:(item.SourceBillID==undefined?'':item.SourceBillID)+"",
							SourceDetailID:(item.SourceDetailID==undefined?'':item.SourceDetailID)+"",
							IsGift:item.IsGift+"",
							ProductionDate:(item.ProductionDate == undefined?'':item.ProductionDate)+"" ,
							validityDate:(item.validityDate == undefined?'':item.validityDate)+"" ,
						};
						Save_D_Data_Json.push(itemData);
					});
				
					console.log(Save_D_Data_Json)
					// // return
					// console.log('打印的商品')
					// console.log(Save_D_Data_Json)
					// return
					if(Save_D_Data_Json.length ==0||Save_D_Data_Json==""||Save_D_Data_Json==undefined){
						GetApi.showTip("请添加商品");
						return
					}
					// length
					if(this.isquote == 1){
						// let data = {
						// 	BillType: 2,
						// 	// Database:"FastApp"
						// 	Save_M_Data_Json: Save_M_Data_Json,
						// 	Save_D_Data_Json: Save_D_Data_Json
						// };
						that.getnewBillNo(1,Save_M_Data_Json,Save_D_Data_Json)
					  
					}else{
						let data = {
							BillID: this.checkdata["BillID"],
							BillType: 2,
							// Database:"FastApp"
							Save_M_Data_Json: JSON.stringify(Save_M_Data_Json),
							Save_D_Data_Json: JSON.stringify(Save_D_Data_Json)
						};
						GetApi.Change_Bill(data, function(res) {
							if (res.state) {
								if (res.data.ErrorMsg == "获取登录信息失败") {
									GetApi.showTip("登录超时");
								} else if (res.data.ErrorMsg != "") {
									GetApi.showTip(res.data.ErrorMsg);
								} else {
									that.OrderGoodsList = [];
									that.CollectAmount = ''
									that.NoSmallAmount = ''
									that.BillRemark = ''
									that.Goodnum = "0"
									that.GoodPrice = '0'
									that.checkdata = []
									GetApi.showTip("保存成功");
									
								}
							} else {
						          GetApi.showTip("服务器错误!");
							}
						});
					}
				}
			},
			// 日期截取
			timesubstr:function(e){
				return e == ""|| e == undefined ? e : e.substring(0,10)
			},
			// 如果是引用单据 则添加引用单据的数据
			details:function(id){
				var that = this;
					let ClientID = uni.getStorageSync("UserCode");
					let CreateName = uni.getStorageSync("UserName");
					let Detailid =  id;
					let data = {
						BillType:1,
						Database:'FastApp',
						BillID:Detailid,
					};
					GetApi.Check_Select_Bill_Order_Detail(data,function(res){
						  if(res.state){
							  console.log(res)
							   if(res.data.ErrorMsg=="获取登录信息失败"){
								   GetApi.showTip("登录超时");
							   }else if(res.data.ErrorMsg!=""){
								   GetApi.showTip(res.data.ErrorMsg);
							   }else{
								   if(res.data.ResultMsg !=""){
									   // console.log('这是请求成功的参数')
									   that.approvedlist = []
									   that.approvedlist = res.data.ResultMsg;
									   console.log('明细的结果')
									   console.log(that.approvedlist)
									   
								   }						   
							   }
						  }else{
							  GetApi.showTip("服务器错误!");
						  }
					});
					
			   that.getnewBillNo(0)
			},
			//如果是引用单据需要重新获取单号
			getnewBillNo:function(e,M_data,D_data){
				var that = this
				let data = {
					BillType:2, 
					Database:'FastApp',
					IsAdd:e,
					BillDate:GetApi.splitdate(that.checkdata.BillTime)
					// BillID:Detailid,
				};
				GetApi.NewOrderNo(data,function(res){
					  if(res.state){
						  console.log(res)
						   if(res.data.ErrorMsg=="获取登录信息失败"){
							   GetApi.showTip("登录超时");
						   }else if(res.data.ErrorMsg!=""){
							   GetApi.showTip(res.data.ErrorMsg);
						   }else{
							   console.log(res)
								that.checkdata.BillNo = res.data.ResultMsg.BillNo
								if(e == 1){
									M_data.BillNo = that.checkdata.BillNo
									let data = {
										BillType: 2,
										// Database:"FastApp"
										Save_M_Data_Json: JSON.stringify(M_data),
										Save_D_Data_Json: JSON.stringify(D_data)
									};
									GetApi.Add_Bill(data, function(res) {
										if (res.state) {
											if (res.data.ErrorMsg == "获取登录信息失败") {
												GetApi.showTip("登录超时");
											} else if (res.data.ErrorMsg != "") {
												GetApi.showTip(res.data.ErrorMsg);
											} else {
												that.OrderGoodsList = [];
												that.CollectAmount = ''
												that.NoSmallAmount = ''
												that.BillRemark = ''
												that.Goodnum = "0"
												that.GoodPrice = '0'
												that.checkdata = []
												// that.checkdata.BillNo = ''
												GetApi.showTip("保存成功");
												if(that.isBillCheckQx){
													that.toBillCheck(res.data.BillID)
												}
												
											}
										} else {
									          GetApi.showTip("服务器错误!");
										}
									});
								}
						   }
					  }else{
						  GetApi.showTip("服务器错误!");
					  }
				});
			}, 
			// 如果是查单
			selectbill:function(e){
				var that = this;
					let ClientID = uni.getStorageSync("UserCode");
					let CreateName = uni.getStorageSync("UserName");
					let Detailid =  e;
					let data = {
						BillType:2,
						Database:'FastApp',
						BillID:Detailid,
					};
					GetApi.Select_Bill_Detail(data,function(res){
						  if(res.state){
							  console.log(res)
							   if(res.data.ErrorMsg=="获取登录信息失败"){
								   GetApi.showTip("登录超时");
							   }else if(res.data.ErrorMsg!=""){
								   GetApi.showTip(res.data.ErrorMsg);
							   }else{
								   that.approvedlist = []
								   that.approvedlist = res.data.ResultMsg
								   // that.source_Good(res.data.ResultMsg)
							   }
						  }else{
							  GetApi.showTip("服务器错误!");
						  }
					});
			},
		    //源单商品与验单商品合并
			source_Good:function(){
				var that = this
				var Goodlist = that.OrderGoodsList;
				var sourceGood = that.approvedlist;
				var batch = false
				if(that.isquote == 1){
					batch = true
				}
				var result = CommonFun.source_Good(Goodlist,sourceGood,batch,that)
				that.OrderGoodsList = result
				this.imputed()
				console.log('执行了')
				console.log(that.OrderGoodsList)
			},
			//价格跟踪
			prices:function(Gooddata){
				// //console.log('打印=============')
				console.log('执行了价格跟踪')
				console.log(Gooddata)
				var that = this;
				let data = {
					// this.NowSelectGoods
					ClientID :that.checkdata["ClientID"],
					StoreID:that.checkdata["StoreID"],
					BillName: "采购入库单",
					GoodsID:Gooddata.GoodsID+"",
					UnitID:Gooddata.UnitID+"",
					URate:Gooddata.urate+"",
					VIPID:''
				}
				 GetApi.XH_Get_PriceFollowMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {
							GetApi.showTip("登录超时");
						} else if (res.data.ErrorMsg != "") {
							GetApi.showTip(res.data.ErrorMsg);
						} else {
							console.log('价格跟踪的第一个')
							console.log(parseFloat(res.data.ResultMsg[0].Price))
							// res.data.ResultMsg[0]["Price"] =  
							
							// Gooddata.Price = parseFloat(res.data.ResultMsg[0].Price)
							//赋值默认
							Gooddata.StoreID = that.checkdata["StoreID"];
							var list =  that.approvedlist;
							var status = false
							var status_Good = null
							for(var i in list){
								if(CommonFun.isidentical(list[i],Gooddata) == true){
									status = true
									status_Good = list[i]
									// IsGift = list[i]["IsGift"]
									// Tax = list[i]["Tax"]
									// Discount = list[i]["Discount"]
									break
								}
							}
							if(status == true){
								Gooddata.IsGift = status_Good.IsGift == "0" ||  status_Good.IsGift == undefined || 
								  status_Good.IsGift == false ||  status_Good.IsGift == ""?"0":'1';
								Gooddata.Tax = status_Good.Tax;
								Gooddata.Discount = status_Good.Discount;
								Gooddata.Price = status_Good.Price;
								
								// Gooddata.BatchNo = this.isnulls(this.timesubstr(status_Good.BatchNo))
								// Gooddata.ProductionDate = this.isnulls(this.timesubstr(status_Good.ProductionDate))
								// Gooddata.validityDate = this.isnulls(this.timesubstr(status_Good.validityDate))
							}else{
								Gooddata.IsGift = "0";
								Gooddata.Tax = "0";
								Gooddata.Discount = "100";
								Gooddata.Price = parseFloat(res.data.ResultMsg[0].Price);
								// Gooddata.Qty = "1";
							}
							Gooddata.Qty = "1";
							Gooddata.Amount = that.computPrice(Gooddata);
							console.log('计算后的数组')
							console.log(Gooddata)
							uni.hideLoading()
							
							var batch = false;
							var CheckGood = that.OrderGoodsList;
							if(that.isquote == 1){
								batch = true
							}
							
							var result = CommonFun.Isbill(list,Gooddata,CheckGood,batch)
									// 如果等于1表示不存在需要提示用户是否继续添加
											if(result.Isbills == 0){
												GetApi.showConfirm("源单明细中没有此商品,是否添加？", function(state) {
													if (state) {
														Gooddata.hasqty = 0
														that.GoodsEach(Gooddata)
													}
												})
											}else if(result.Isgreater== 1){
												GetApi.showConfirm("录入的数量大于源单数量,是否添加？", function(state,) {
													if (state) {
														Gooddata.hasqty = 0
														that.GoodsEach(Gooddata)
													}
												})
											}else{
												that.GoodsEach(Gooddata)
											}
						}
					} else {
							GetApi.showTip("服务器错误!");
					}
				});
			},
			// isnulls:function(e){
			// 	return e == "" || typeof e == 'undefined' ?"":e
			// },
			clickmore:function(){
				this.more = !this.more
			},
			//计算金额
			computPrice(data){
				var Price = 0;
				//console.log('进来的参数')
				//console.log(item)
				// parseFloat((item.PFPrice*item.Qty*(item.Discount/100)*(1+item.Tax/100))).toFixed(2);
				Price = parseFloat((data.Price*data.Qty*(data.Discount/100)*(1+data.Tax/100))).toFixed(2);
				//console.log('计算后的金额')
				//console.log(Price)
				var Pr =Math.round(Price * 100) / 100;
				console.log("555550",Pr)
				return Pr;
			},
			onNavigationBarButtonTap(e) {
				console.log('点击了导航设置')
				console.log(e)
				var that = this
				const index = e.index;
				if (index === 0) {
				   	that.$refs.Drawer.open(this.checkdata.BillNo ==""||this.checkdata.BillNo == undefined?false:true,this.isquote);
				} 
			},
		}
	}
</script>

<style>
	@import url("/validation.css");
	page {
		background-color: #EEEEEE;
		padding-bottom: 0upx;
		height: 100%;
	}
	.list_img{
		width: 33%;float: left;border-radius: 5px;height: 100%;
	}
</style>
